import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
// 导入字体图标
import './assets/fonts/iconfont.css'
axios.defaults.baseURL = 'https://www.liulongbin.top:8888/api/private/v1'
// 树状图
import TreeTable from 'vue-table-with-tree-grid'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
// 图表

import echarts from "echarts";
import _ from "lodash";


Vue.use(ElementUI);
//请求在到达服务器之前，先会调用use中的这个回调函数来添加请求头信息
axios.interceptors.request.use(config => {
  //为请求头对象，添加token验证的Authorization字段
  config.headers.Authorization = window.sessionStorage.getItem("token")
  return config
})
Vue.component('tree-table', TreeTable)
Vue.use(VueQuillEditor)
// 全局路由守卫
router.beforeEach((to, from, next) => {
  let token = window.sessionStorage.getItem("token")
  if (to.path == "/login") {
    next()
  } else {
    //需要验证是否登录成功
    if (token) {
      next()
    } else {
      next("/login")
    }
  }
})

Vue.filter('dateFormat', (originVal) => {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + 1 + '').padStart(2, '0')
  const hh = (dt.getHours() + 1 + '').padStart(2, '0')
  const mm = (dt.getMinutes() + 1 + '').padStart(2, '0')
  const ss = (dt.getSeconds() + 1 + '').padStart(2, '0')
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

Vue.config.productionTip = false
Vue.prototype.$http = axios
Vue.prototype.$echarts = echarts


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
